var root=ui("$");
var page = sm("do_Page");
var nf = sm("do_Notification");
var helperOpen = require("helper/open");
var helperOrder = require("helper/order");
var qqmath = require("util/qqmath");
var do_Label_num = ui("do_Label_num");
var do_ALayout_order = ui("do_ALayout_order");
var do_ImageView_img = ui("do_ImageView_img");
var do_Label_title = ui("do_Label_title");
var do_Label_time = ui("do_Label_time");
var do_Label_orderStatus = ui("do_Label_orderStatus");
var do_Label_total = ui("do_Label_total");
//var layoutBtn = ui("layoutBtn");
var do_Button_delivery = ui("do_Button_delivery");
var do_Button_cancel = ui("do_Button_cancel");
var do_Button_aduit = ui("do_Button_aduit");
//设置数据绑定的映射关系
root.setMapping({
	"do_Label_num.tag":"orderNo",
	"do_ImageView_img.source":"pathImg",
	"do_Label_title.text":"title",
	"do_Label_title.tag":"orderType",
	"do_Label_time.text":"strNewAt",
	"do_Label_orderStatus.tag":"orderStatus",
	"do_Label_total.text":"total",
	"do_Label_10.text" :"buyerNick",
	"do_Label_orderStatus.text" : "orderStatusText",
	//"layoutBtn.visible" : "hasBtn",
	"do_Button_delivery.visible" : "showDelivery",
	"do_Button_cancel.visible" : "showCancel",
	"do_Button_aduit.visible" : "showReturnAudit"
});


root.on("dataRefreshed", function(){
	do_Label_num.text = "No."+do_Label_num.tag;
	do_Label_total.text = "总计：￥" + qqmath.getDight(do_Label_total.text,2);
});

do_ALayout_order.on("touch", function(data){
	var orderNo = do_Label_num.tag;
	helperOpen.open("source://view/order/supplier/detail.ui", {orderNo : orderNo});
});

do_Button_delivery.on("touch", function(data){
	var orderNo = do_Label_num.tag;
	if(do_Label_title.tag == 6){
		nf.confirm("确认发货?", "", "确定", "取消", function(data, e) {
			if (data == 1) {
				helperOrder.sellerSended(orderNo,'2',null,null,'1',function(data,e){
					do_Label_orderStatus.text = "已发货";
					do_Button_delivery.visible=false;
				});
			}
		});
	}
});

do_Button_aduit.on("touch", function(data){
	var orderNo = do_Label_num.tag;
	nf.confirm("是否同意买家退款申请?", "", "同意退款", "驳回申请", function(data, e) {
		if (data == 1) {
			helperOrder.sellerAgreeReturnPay(orderNo,function (){
				do_Label_orderStatus.text = "退款完成";
				do_Button_delivery.visible = false;
				do_Button_cancel.visible = false;
				do_Button_aduit.visible = false;
			});
		}else{
			helperOrder.sellerRefuseReturnPay(orderNo,function (){
				do_Label_orderStatus.text = "拒绝退款";
				do_Button_delivery.visible = false;
				do_Button_cancel.visible = false;
				do_Button_aduit.visible = false;
			});
		}
	});
});

do_Button_cancel.on("touch", function(data){
	var orderNo = do_Label_num.tag;
	nf.confirm("确定取消订单?", "", "确定", "我再想想", function(data, e) {
		if (data == 1) {
			helperOrder.buyerCancel(orderNo,function (){
				do_Label_orderStatus.text = "已取消";
				//layoutBtn.visible = false;
			});
		}
	});
});